package com.shinhye.demoproject.util;

import android.util.Log;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * log类
 *
 * @author wl
 * @since 2014-12-21 下午1:58:31
 */
public class WLog {
	public static boolean DEBUG = true;
	public final static String TAG = "EastLending";

	public static void setDebug(boolean debug){
		DEBUG = debug;
	}

	public static void i(String tag, String msg) {
		if (DEBUG)
			Log.i(tag, msg);
	}

	public static void e(String tag, String msg) {
		if (DEBUG)
			Log.e(tag, msg);
	}

	public static void d(String tag, String msg) {
		if (DEBUG)
			Log.d(tag, msg);
	}
	
	public static void w(String tag, String msg) {
		if (DEBUG)
			Log.w(tag, msg);
	}
	
	public static void v(String tag, String msg) {
		if (DEBUG)
			Log.v(tag, msg);
	}

	public static void i(String msg) {
		if (DEBUG)
			Log.i(TAG, msg);
	}

	public static void e(String msg) {
		if (DEBUG)
			Log.e(TAG, msg);
	}

	public static void d(String msg) {
		if (DEBUG)
			Log.d(TAG, msg);
	}
	
	public static void w(String msg) {
		if (DEBUG)
			Log.w(TAG, msg);
	}
	
	public static void v(String msg) {
		if (DEBUG)
			Log.v(TAG, msg);
	}

	/*
 	* 得到当前代码文件名和行号
 	* */
	public static String getLineInfo(){
		if(DEBUG){
			StackTraceElement ste = new Throwable().getStackTrace()[1];
			//return "Filename:"+ste.getFileName() + ": Line " + ste.getLineNumber()+"\n";
			return "Line " + ste.getLineNumber()+"\n";
		}else{
			return " ";
		}
	}

	public static void printStack(String string) {
		if (DEBUG) {
			StackTraceElement[] stack = Thread.currentThread().getStackTrace();
			StringBuffer print = new StringBuffer();
			print.append("Call ").append(stack[3].getMethodName()).append(":\n");
			for (int i = 3; i < stack.length; i++) {
				print.append("          at ").append(stack[i].toString()).append("\n");
				if( i > 20 )
					break;
			}
			d(string+" ="+print.toString());
		}
	}

	public static void printStack(String tag, String string) {
		if (DEBUG) {
			StackTraceElement[] stack = Thread.currentThread().getStackTrace();
			StringBuffer print = new StringBuffer();
			print.append("Call ").append(stack[3].getMethodName()).append(":\n");
			for (int i = 3; i < stack.length; i++) {
				print.append("          at ").append(stack[i].toString()).append("\n");
				if( i > 20 )
					break;
			}

			d(TAG, string+" ="+print.toString());
			if(tag!=null){
				d(tag, string+" ="+print.toString());
			}
		}
	}

	public static void printfdateAndtime(String string){
		String   str   =   getdateAndtime();
		if(DEBUG){
			d(TAG,string+":"+ str.toString());
		}
	}

	public static void printfdateAndtime(String tag,String string){
		String   str   =   getdateAndtime();
		if(DEBUG){
			Log.d(TAG,string+":"+ str.toString());
			if(tag!=null){
				d(tag, string + ":" + str.toString());
			}
		}
	}

	public static String getdateAndtime(){
		SimpleDateFormat formatter   =   new   SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
		Date curDate   =   new   Date(System.currentTimeMillis());
		String   str   =   formatter.format(curDate);
		return str;
	}
}
